/**
 * @author lteng
 * @time 2022-06-18 14:48:40 
 */

package liteng.study.cn.stuscore.service.impl;

import java.util.Map;

import liteng.study.cn.stuscore.comm.Page;
import liteng.study.cn.stuscore.dao.EProjectDao;
import liteng.study.cn.stuscore.dao.ETypeDao;
import liteng.study.cn.stuscore.dao.ExamDao;
import liteng.study.cn.stuscore.dao.GradeDao;
import liteng.study.cn.stuscore.dao.impl.EProjectDaoImpl;
import liteng.study.cn.stuscore.dao.impl.ETypeDaoImpl;
import liteng.study.cn.stuscore.dao.impl.ExamDaoImpl;
import liteng.study.cn.stuscore.dao.impl.GradeDaoImpl;
import liteng.study.cn.stuscore.entity.EProject;
import liteng.study.cn.stuscore.entity.EType;
import liteng.study.cn.stuscore.entity.Exam;
import liteng.study.cn.stuscore.entity.Grade;
import liteng.study.cn.stuscore.service.ExamService;

/**
 * 考试信息业务层实现类
 */
public class ExamServiceImpl implements ExamService {

	private ETypeDao eTypeDao = new ETypeDaoImpl();
	private ExamDao examDao = new ExamDaoImpl();
	private EProjectDao eProjectDao = new EProjectDaoImpl();
	private GradeDao gradeDao = new GradeDaoImpl();

	@Override
	public void add(Exam exam) {
		// TODO Auto-generated method stub
		examDao.add(exam);
	}

	@Override
	public void update(Exam exam) {
		// TODO Auto-generated method stub
		examDao.update(exam);
	}

	@Override
	public void delete(Exam exam) {
		// TODO Auto-generated method stub
		examDao.delete(exam);
	}

	@Override
	public Exam getOne(int id) {
		// TODO Auto-generated method stub
		return examDao.qryOne(id);
	}

	@Override
	public Page getPageExams(int pageIndex, int PageSize) {
		// TODO Auto-generated method stub
		Page page = examDao.qryExams(pageIndex, PageSize);
		for (Map<String, Object> map : page.getData()) {
			int epId = (int) map.get("epid");
			int etId = (int) map.get("etid");
			int gId = (int) map.get("gid");

			EType eType = eTypeDao.qryOne(etId);
			EProject eProject = eProjectDao.qryOne(epId);
			Grade grade = gradeDao.qryOne(gId);

			map.put("tname", eType.getName());
			map.put("pname", eProject.getName());
			map.put("gname", grade.getName());
		}
		return page;
	}

	@Override
	public Page getPageExams(int pageIndex, int PageSize, String name) {
		// TODO Auto-generated method stub
		Page page = examDao.qryExams(pageIndex, PageSize, name);
		for (Map<String, Object> map : page.getData()) {
			int epId = (int) map.get("epid");
			int etId = (int) map.get("etid");
			int gId = (int) map.get("gid");

			EType eType = eTypeDao.qryOne(etId);
			EProject eProject = eProjectDao.qryOne(epId);
			Grade grade = gradeDao.qryOne(gId);

			map.put("tname", eType.getName());
			map.put("pname", eProject.getName());
			map.put("gname", grade.getName());
		}
		return page;
	}

}
